package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import com.sun.corba.se.impl.oa.poa.POAPolicyMediatorImpl_NR_UDS;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/axios")
public class AxiosController {

    @Autowired
    private UserService userService;
    @GetMapping("/getUserById")
    public User getUserById(Integer id){
        return userService.findUserById(id);
    }

    @GetMapping("/user/{sex}/{age}")
    public List<User> getUserBySA(User user){
        return userService.getUserBySA(user);
    }

    @GetMapping("/getUser")
    public List<User> getUser(User user){
        return userService.getUser(user);
    }

    @DeleteMapping("/deletById")
    public String deletById(Integer id){
        userService.deletById(id);
        return "删除数据成功！！";
    }

    @PostMapping("/saveUser")
    public String saveUser(@RequestBody User user){

        userService.saveUser(user);
        return "添加信息成功！！";
    }

    @PutMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        userService.updateUser(user);
        return "修改成功";
    }

    @PutMapping("/updateUser/{whereName}")
    public String updateUser2(@RequestBody User user,
                              @PathVariable String whereName){
        userService.updateUser2(user,whereName);
        return "修改成功222";
    }
}
